package com.hendraanggrian.appcompat.widget;

import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Base interface of all social widgets, which usually derived from {@link Text}.
 * Out of the box, there are {@link SocialTextView}, {@link SocialEditText}, and {@code SocialAutoCompleteTextView}.
 * It can also be implemented in any {@link ohos.agp.components.Component}
 * using {@link SocialViewHelper}.
 */
public interface SocialView {
    /**
     * Returns regex that are responsible for finding <b>hashtags</b>.
     * By default, the pattern are {@code #(\w+)}.
     *
     * @return Pattern
     */
    Pattern getHashtagPattern();

    /**
     * Returns regex that are responsible for finding <b>mentions</b>.
     * By default, the pattern are {@code @(\w+)}.
     *
     * @return Pattern
     */
    Pattern getMentionPattern();

    /**
     * Returns regex that are responsible for finding <b>hyperlinks</b>.
     * By default, the pattern are {@link PatternsCompat#WEB_URL}.
     *
     * @return Pattern
     */
    Pattern getHyperlinkPattern();

    /**
     * Modify regex that are responsible for finding <b>hashtags</b>.
     *
     * @param pattern custom regex. When null, default pattern will be used.
     */
    void setHashtagPattern( Pattern pattern);

    /**
     * Modify regex that are responsible for finding <b>hashtags</b>.
     *
     * @param pattern custom regex. When null, default pattern will be used.
     */
    void setMentionPattern( Pattern pattern);

    /**
     * Modify regex that are responsible for finding <b>hashtags</b>.
     *
     * @param pattern custom regex. When null, default pattern will be used.
     */
    void setHyperlinkPattern( Pattern pattern);

    /**
     * Returns true if <b>hashtags</b> in this view are spanned.
     *
     * @return 是否选中
     */
    boolean isHashtagEnabled();

    /**
     * Returns true if <b>mentions</b> in this view are spanned.
     *
     * @return 是否选中
     */
    boolean isMentionEnabled();

    /**
     * Returns true if <b>hyperlinks</b> in this view are spanned.
     *
     * @return 是否选中
     */
    boolean isHyperlinkEnabled();

    /**
     * Determine whether this view should span <b>hashtags</b>.
     *
     * @param enabled True when spanning should be enabled.
     */
    void setHashtagEnabled(boolean enabled);

    /**
     * Determine whether this view should span <b>mentions</b>.
     *
     * @param enabled True when spanning should be enabled.
     */
    void setMentionEnabled(boolean enabled);

    /**
     * Determine whether this view should span <b>hyperlinks</b>.
     *
     * @param enabled True when spanning should be enabled.
     */
    void setHyperlinkEnabled(boolean enabled);

    /**
     * Registers a callback to be invoked when a <b>hashtag</b> is clicked.
     *
     * @param listener The callback that will run.
     */
    void setOnHashtagClickListener(OnClickListener listener);

    /**
     * Registers a callback to be invoked when a <b>mention</b> is clicked.
     *
     * @param listener The callback that will run.
     */
    void setOnMentionClickListener(OnClickListener listener);

    /**
     * Registers a callback to be invoked when a <b>hyperlink</b> is clicked.
     *
     * @param listener The callback that will run.
     */
    void setOnHyperlinkClickListener( OnClickListener listener);

    /**
     * Registers a text watcher to be invoked when a <b>hashtag</b> is modified.
     *
     * @param listener The callback that will run.
     */
    void setHashtagTextChangedListener( OnChangedListener listener);

    /**
     * Registers a text watcher to be invoked when a <b>mention</b> is modified.
     *
     * @param listener The callback that will run.
     */
    void setMentionTextChangedListener( OnChangedListener listener);

    /**
     * Returns list of all <b>hashtags</b> found in {@link Text#getText()}.
     *
     * @return Hashtags
     */
    List<String> getHashtags();

    /**
     * Returns list of all <b>mentions</b> found in {@link Text#getText()}.
     *
     * @return Mentions
     */
    List<String> getMentions();

    /**
     * Returns list of all <b>hyperlinks</b> found in {@link Text#getText()}.
     *
     * @return links
     */
    List<String> getHyperlinks();

    /**
     * 输入内容
     *
     * @param text 内容
     * @return 内容
     */
    CharSequence terminateToken(CharSequence text);

    /**
     * 开始输入的位置
     *
     * @param text 内容
     * @param cursor 光标位置
     * @param listContainer listContainer
     * @return 开始输入的位置
     */
    int findTokenStart(CharSequence text, int cursor , ListContainer listContainer);

    /**
     * Interface definition for a callback to be invoked when a <b>hashtag</b>,
     * <b>mention</b>, or <b>hyperlink</b> is clicked.
     */
    interface OnClickListener {
        /**
         * Called when a text has been clicked.
         *
         * @param view The view that the texts belong to.
         * @param text The text that was clicked.
         */
        void onClick( SocialView view,  CharSequence text);
    }

    /**
     * Interface definition for a callback to be invoked when a <b>hashtag</b>,
     * <b>mention</b>, or <b>hyperlink</b> is modified.
     */
    interface OnChangedListener {
        /**
         * Called when a text has been modified.
         *
         * @param view The view that the texts belong to.
         * @param text The text that was modified.
         */
        void onChanged( SocialView view,  CharSequence text);
    }
}